import * as types from '../mutation-types.js'
import { store } from '../../utils/store/store.js'


const state = {
    userInfo: store.get('userInfo') || {}
}

const getters = {
    userInfo(state) {
        return state.userInfo
    },
    userToken(state) {
        return state.userInfo && state.userInfo.token ? state.userInfo.token : ''
    }
}

const actions = {
    set_userInfo: ({ commit }, userInfo) => {
        return new Promise((resolve, reject) => {
            commit(types.SET_USERINFO, userInfo)
            resolve()
        })
    },
}

const mutations = {
    [types.SET_USERINFO](state, userInfo) {
        state.userInfo = userInfo || {}
        store.set('userInfo', state.userInfo)
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}